package config

import (
	"fmt"
	"github.com/spf13/viper"
)

type ObsConfig struct {
	Ak       string
	Sk       string
	Endpoint string
}

func (o ObsConfig) String() string {
	return fmt.Sprintf("ak: %s, sk: %s, endpoint: %s", o.Ak, o.Sk, o.Endpoint)
}

type CommandConfig struct {
	HotelCommandConfigFile string
	MallCommandConfigFile  string
}

func Init(cfg string) error {
	if cfg != "" {
		viper.SetConfigFile(cfg)
	} else {
		viper.SetConfigName("app")
		viper.SetConfigType("yaml")
		viper.AddConfigPath("/etc/obs")
		viper.AddConfigPath("$HOME/.obs")
		viper.AddConfigPath(".")
	}
	return viper.ReadInConfig()
}

func NewObsConfig() *ObsConfig {
	return &ObsConfig{
		Ak:       viper.GetString("obs.ak"),
		Sk:       viper.GetString("obs.sk"),
		Endpoint: viper.GetString("obs.endpoint"),
	}
}

func NewCommandConfig() *CommandConfig {
	return &CommandConfig{
		MallCommandConfigFile:  viper.GetString("command.mall"),
		HotelCommandConfigFile: viper.GetString("command.hotel"),
	}
}
